package com.ruoyi.lagou.mybatis.mapper;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * user表的注解开发形式
 * @author li_hai
 */
public interface SysUserAnnotationMapper {

    /**
     * 通过用户ID查询用户
     *
     * @param userId 用户ID
     * @return 用户对象信息
     */
    @Select("select * from sys_user where user_id = #{userId}")
    SysUser selectUserById(Long userId);

    /**
     * 一对一关系
     * @param userId    参数
     * @return  结果
     */
    @Select("select * from sys_user where user_id = #{userId} ")
    @Results(id = "userMap", value = {
            @Result(property = "userId", column = "user_id"),
            @Result(property = "deptId", column = "dept_id"),
            @Result(property = "dept", column = "dept_id", one = @One(select = "com.ruoyi.system.mapper.SysDeptMapper.selectDeptById"))
    })
    SysUser selectUserAndDeptById(Long userId);

}
